home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / borcmpad / mpinit.c < prev    next >
C/C++ Source or Header  |  1991-07-23  |  5KB  |  169 lines

  1. /***************************************************************************
  2.  *                                       *
  3.  *  MODULE    : MpInit.c                           *
  4.  *                                       *
  5.  *  PURPOSE    : Contains initialization code for MultiPad.           *
  6.  *                                       *
  7.  *  FUNCTIONS    : InitializeApplication() - Sets up Class data structure   *
  8.  *                        and registers window class.    *
  9.  *                                       *
  10.  *          InitializeInstance ()   - Does a per-instance initial-   *
  11.  *                        ization of MultiPad. Creates   *
  12.  *                        the "frame" and MDI client.    *
  13.  *                                       *
  14.  ***************************************************************************/
  15. #include "multipad.h"
  16.  
  17. char szFrame[] = "mpframe";   /* Class name for "frame" window */
  18. char szChild[] = "mpchild";   /* Class name for MDI window     */
  19.  
  20. /****************************************************************************
  21.  *                                        *
  22.  *  FUNCTION   : InitializeApplication ()                    *
  23.  *                                        *
  24.  *  PURPOSE    : Sets up the class data structures and does a one-time        *
  25.  *         initialization of the app by registering the window classes*
  26.  *                                        *
  27.  *  RETURNS    : TRUE  - If RegisterClass() was successful for both classes.*
  28.  *         FALSE - otherwise.                        *
  29.  *                                        *
  30.  ****************************************************************************/
  31.  
  32. BOOL FAR PASCAL InitializeApplication()
  33. {
  34.     WNDCLASS    wc;
  35.  
  36.     /* Register the frame class */
  37.     wc.style         = 0;
  38.     wc.lpfnWndProc   = MPFrameWndProc;
  39.     wc.cbClsExtra    = 0;
  40.     wc.cbWndExtra    = 0;
  41.     wc.hInstance     = hInst;
  42.     wc.hIcon         = LoadIcon(hInst,IDMULTIPAD);
  43.     wc.hCursor         = LoadCursor(NULL,IDC_ARROW);
  44.     wc.hbrBackground = COLOR_APPWORKSPACE;
  45.     wc.lpszMenuName  = IDMULTIPAD;
  46.     wc.lpszClassName = szFrame;
  47.  
  48.     if (!RegisterClass (&wc) )
  49.     return FALSE;
  50.  
  51.     /* Register the MDI child class */
  52.     wc.lpfnWndProc   = MPMDIChildWndProc;
  53.     wc.hIcon         = LoadIcon(hInst,IDNOTE);
  54.     wc.lpszMenuName  = NULL;
  55.     wc.cbWndExtra    = CBWNDEXTRA;
  56.     wc.lpszClassName = szChild;
  57.  
  58.     if (!RegisterClass(&wc))
  59.     return FALSE;
  60. /**/
  61. /* register the status line class */
  62.    wc.cbClsExtra    = 0;
  63.    wc.cbWndExtra    = 0;
  64.    wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  65.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  66.    wc.hIcon         = NULL;
  67.    wc.hInstance     = hInst;
  68.    wc.lpfnWndProc   = StatusWndProc;
  69.    wc.lpszMenuName  = NULL;
  70.    wc.lpszClassName = "StatClass";
  71.    wc.style         = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  72.  
  73.     if (!RegisterClass(&wc))
  74.         return FALSE;
  75. /**/
  76.  
  77.     return TRUE;
  78.  
  79. }
  80.  
  81. /****************************************************************************
  82.  *                                        *
  83.  *  FUNCTION   : InitializeInstance ()                        *
  84.  *                                        *
  85.  *  PURPOSE    : Performs a per-instance initialization of MultiPad. It     *
  86.  *         also creates the frame and an MDI window.            *
  87.  *                                        *
  88.  *  RETURNS    : TRUE  - If initialization was successful.            *
  89.  *         FALSE - otherwise.                        *
  90.  *                                        *
  91.  ****************************************************************************/
  92. BOOL FAR PASCAL InitializeInstance(LPSTR lpCmdLine, WORD nCmdShow)
  93. {
  94.     extern HWND  hwndMDIClient;
  95.     char     sz[80], *pCmdLine;
  96.  
  97.     /* Get the base window title */
  98.     LoadString (hInst, IDS_APPNAME, sz, sizeof(sz));
  99.  
  100.     /* Create the frame */
  101.     hwndFrame = CreateWindow (szFrame,
  102.                   sz,
  103.                   WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  104.                   CW_USEDEFAULT,
  105.                   0,
  106.                   CW_USEDEFAULT,
  107.                   0,
  108.                   NULL,
  109.                   NULL,
  110.                   hInst,
  111.                   NULL);
  112.  
  113.     /* Windows calls the MPFrameWndProc() that processes a message */
  114.     /* to initialize hwndMDIClient as a result of the above call on */
  115.     /* CreateWindow().  This initialization is an intended side-effect. */
  116.  
  117.     if (!hwndFrame || !hwndMDIClient)
  118.     return FALSE;
  119. /**/
  120.  
  121.     /* Create the status window.  By the time we reach this point, the frame
  122.        and MDI client windows already exist
  123.     */
  124.     hStatWnd = CreateWindow("StatClass",
  125.                            NULL,
  126.                            WS_CHILD | WS_VISIBLE | WS_BORDER,
  127.                            0,0,0,0,
  128.                            hwndFrame, /* the parent                        */
  129.                            NULL,      /* Use the window class menu.        */
  130.                            hInst,     /* This instance owns this window.   */
  131.                            NULL       /* Pointer not needed.               */
  132.                );
  133.  
  134.     if (!hStatWnd)
  135.        return (FALSE);
  136. /**/
  137.     /* Load main menu accelerators */
  138.     if (!(hAccel = LoadAccelerators (hInst, IDMULTIPAD)))
  139.     return FALSE;
  140.  
  141.     /* Display the frame window */
  142.     ShowWindow (hwndFrame, nCmdShow);
  143.     UpdateWindow (hwndFrame);
  144.  
  145.     /* If the command line string is empty, nullify the pointer to it 
  146.     ** else copy command line into our data segment 
  147.     */
  148.     if (lpCmdLine && !(*lpCmdLine))
  149.          pCmdLine = NULL;
  150.     else {
  151.         pCmdLine = (char *) LocalAlloc(LPTR, lstrlen(lpCmdLine) + 1);
  152.         if (pCmdLine)
  153.            lstrcpy(pCmdLine, lpCmdLine);
  154.     }
  155.  
  156.     /* Add the first MDI window */
  157.     AddFile (pCmdLine);
  158.  
  159.     /* if we allocated a buffer then free it */
  160.     if (pCmdLine)
  161.         LocalFree((LOCALHANDLE) pCmdLine);
  162.  
  163.     /* Default to minimized windows after the first. */
  164.     styleDefault = 0L;
  165.  
  166.     return TRUE;
  167.  
  168. }
  169.